package com.daocao.ds.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daocao.ds.R;
import com.daocao.ds.base.BaseActivity;
import com.daocao.ds.constant.UserInfoGlobal;
import com.daocao.ds.util.UI;
import com.daocao.ds.util.Util;
import com.daocao.ds.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/10.
 */

public class GestureSettingActivity extends BaseActivity {

    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.txt_gesture_pass)
    TextView txtGesturePass;
    @BindView(R.id.btn_gesture_open)
    ImageView btnGestureOpen;
    @BindView(R.id.btn_gesture_pass)
    LinearLayout btnGesturePass;
    @BindView(R.id.txt_gesture_root)
    TextView txtGestureRoot;
    @BindView(R.id.btn_gesture_root_open)
    ImageView btnGestureRootOpen;
    @BindView(R.id.btn_gesture_root)
    LinearLayout btnGestureRoot;
    @BindView(R.id.txt_gesture_pass_set)
    TextView txtGesturePassSet;
    @BindView(R.id.btn_gesture_pass_set)
    LinearLayout btnGesturePassSet;
    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guesture_setting);
        initBar();
        unbinder = ButterKnife.bind(this);
        init();
    }

    private void init() {
        setIsNeedCheckLogout(false);
        txtTitle.setText("手势密码");

    }

    @Override
    protected void onResume() {
        super.onResume();
        initbutton();
    }

    private void initbutton() {
        if (UserInfoGlobal.getIsOpenGuesture()) {
            btnGestureOpen.setImageResource(R.mipmap.img_gesture_open);
        } else {
            btnGestureOpen.setImageResource(R.mipmap.img_gesture_close);
        }
        if (UserInfoGlobal.getIsOpenGuestureRoot()) {
            btnGestureRootOpen.setImageResource(R.mipmap.img_gesture_open);
        } else {
            btnGestureRootOpen.setImageResource(R.mipmap.img_gesture_close);
        }
        if (isSetGuesture()) {
//            switchBtn.setEnabled(true);
            txtGesturePassSet.setText("修改手势密码");

        } else {
//            switchBtn.setEnabled(false);
            txtGesturePassSet.setText("设置手势密码");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        unbinder = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }

    @OnClick(R.id.btn_gesture_pass_set)
    public void onViewClicked1() {
        if (UI.toString(txtGesturePassSet).equals("设置手势密码")) {
            Intent intent = new Intent(this, CreateGestureActivity.class);
            intent.putExtra("is_check", true);
            startActivity(intent);
            overridePendingTransition(R.anim.right_enter, R.anim.left_out);
        } else {
            Intent intent = new Intent(this, GestureLoginActivity.class);
            intent.putExtra("is_check", true);
            startActivity(intent);
            overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                    Util.startActivity(this, GestureLoginActivity.class);
        }
    }

    @OnClick({R.id.btn_gesture_open, R.id.btn_gesture_root_open})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_gesture_open:
                if (!isSetGuesture()) {
                    Util.startActivity(this, CreateGestureActivity.class);
                    return;
                }
                if (UserInfoGlobal.getIsOpenGuesture()) {
                    UserInfoGlobal.setIsOpenGuesture(false);
                    btnGestureOpen.setImageResource(R.mipmap.img_gesture_close);
                } else {
                    UserInfoGlobal.setIsOpenGuesture(true);
                    btnGestureOpen.setImageResource(R.mipmap.img_gesture_open);
                }
                break;
            case R.id.btn_gesture_root_open:
                if (UserInfoGlobal.getIsOpenGuestureRoot()) {
                    UserInfoGlobal.setIsOpenGuestureRoot(false);
                    btnGestureRootOpen.setImageResource(R.mipmap.img_gesture_close);
                } else {
                    UserInfoGlobal.setIsOpenGuestureRoot(true);
                    btnGestureRootOpen.setImageResource(R.mipmap.img_gesture_open);
                }
                break;
        }
    }
}
